﻿
namespace TimetableCSP.Scheduler.Entities
{
	/// <summary>
	/// This constraint guarantees that no two classes from the same course are taught on the same day.
	/// </summary>
	public class SameDayConstraint : BinaryConstraint
	{
		public const int TeachingDaysInAWeek = 5;

		/// <summary>
		/// Determines whether there's a conflict between the two variables.
		/// </summary>
		/// <param name="a">The first variable.</param>
		/// <param name="b">The second variable.</param>
		/// <param name="conflictingAttributes">If there's a conflict, then this array holds the names of those attributes that need to be modified in order to solve the conflict.</param>
		/// <returns>
		///   <c>true</c> if there's a conflict; otherwise, <c>false</c>.
		/// </returns>
		public override bool IsConflict(AbstractVariable a, AbstractVariable b, out string[] conflictingAttributes)
		{
			conflictingAttributes = null;
			ClassVariable classA = (ClassVariable)a;
			ClassVariable classB = (ClassVariable)b;

			if (	classA.CourseId.Length > 0 &&
					classA.CourseId == classB.CourseId &&
					( classA.Timeslot / TeachingDaysInAWeek ) == ( classB.Timeslot / TeachingDaysInAWeek )
				)
			{
#if DEBUG_EXTRA
				System.Diagnostics.Debug.WriteLine("Same day conflict");
				System.Diagnostics.Debug.WriteLine("\tA: " + classA);
				System.Diagnostics.Debug.WriteLine("\tB: " + classB);
#endif
				conflictingAttributes = new string[] { ClassVariable.TimeslotAttributeName };
				ConflictCount++;
				return true;
			}
			return false;
		}

	}
}
